<template>
  <div>
    <el-tree :data="list"
             :props="defaultProps"
             node-key="catId"
             @node-click="nodeClick"
             ref="tree">
      <span class="custom-tree-node" slot-scope="{ node, data }">
        <span>{{ node.label }}</span>
      </span>
    </el-tree>
  </div>
</template>

<script>
  export default {
    name: "category",
    data(){
      return{
        list: [],  //树形结构的数据
        expandedKey: [], //删除节点原地展开
        defaultProps: {
          children: 'children',
          label: 'name'
        }
      }
    },
    created() {
      this.getMenus()
    },
    methods: {
      getMenus() {
        this.$http({
          url: this.$http.adornUrl('/product/category/list/tree'),
          method: 'get',
        }).then(res=>{
          this.list = res.data.entities
        })
      },
      nodeClick(data,Node,component) {
        console.log("子组件被点击：",data,Node,component)
        this.$emit("tree-node-click",data,Node,component)
      }
    },
  }
</script>

<style scoped>

</style>
